package com.lib.application;

import com.lib.dto.RentalAgentApplyDTO;
import com.lib.dto.RentalAgentApplyMessageDTO;
import com.lib.dto.enums.RentalAgentTextEnum;
import com.lib.model.ShopQRCode;
import com.lib.repository.ShopQRCodeRepository;
import com.lib.service.WxAgentService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by duqingxiang on 17/5/23.
 */
@Service
public class RentalAgentMessageService {

    @Autowired
    TemplateService templateService;

    @Autowired
    ShopQRCodeRepository shopQRCodeRepository;

    @Autowired
    WxAgentService wxAgentService;

    public String getNormalMessage(){
        return templateService.getTemplateContent(null, RentalAgentTextEnum.REGISTER_TEXT.getTemplate());
    }

    public String getScanQRCodeMessage(int param,WxMpXmlMessage wxMessage){

        //TODO 根据二维码参数获取实际参数

        //TODO 获取经纪人信息

        //TODO 替换文字信息

        ShopQRCode code = shopQRCodeRepository.findShopQRCodeById(param);
        if (code == null)
            return null;

        RentalAgentApplyMessageDTO messageDTO = RentalAgentApplyMessageDTO.builder()
                .shopId(code.getShopId()+"")
                .shopName(code.getShopName())
                .openId(wxMessage.getFromUser())
                .build();

        return templateService.getTemplateContent(messageDTO, RentalAgentTextEnum.REGISTER_SCAN_TEXT.getTemplate());
    }


}
